class FriendshipsController < ApplicationController

  before_filter :login_required
  before_filter :find_user

  def send_request
    current_user.request_friendship_with(@user)
    UserMailer.deliver_friend_request(:to    => @user,
                              :from  => current_user,
                              :link  => home_profile_url(@user.login))
    respond_to do |format|
      flash[:notice] = "A colleague request has been issued to #{@user.name}"
      format.html { redirect_to :back }
    end

  end

  def create
    current_user.accept_friendship_request_from(@user)

    respond_to do |format|
      format.html { redirect_to home_profile_url(current_user.login)}
    end

  end

  def decline
    current_user.decline_friendship_request_from(@user)

    respond_to do |format|
      format.html { redirect_to home_profile_url(current_user.login)}
    end

  end

  def destroy
    current_user.destroy_friendship_with(@user)

    respond_to do |format|
      format.html { redirect_to home_profile_url(current_user.login)}
    end

  end

  def withdraw
    current_user.withdraw_friendship_request_to(@user)

    respond_to do |format|
      format.html { redirect_to home_profile_url(current_user.login)}
    end

  end

end
